package de.baumann.browser.activitys.node

import android.content.Context
import android.content.Intent
import android.support.v7.widget.LinearLayoutManager
import de.baumann.browser.R
import de.baumann.browser.adapter.NodeMemberListAdapter
import de.baumann.browser.api.net.vo.Member
import de.baumann.browser.base.BaseOdinActivity
import de.baumann.browser.iview.INodeMembersView
import de.baumann.browser.present.NodeMemberPresenter
import kotlinx.android.synthetic.main.activity_node_member.*
import kotlinx.android.synthetic.main.include_tool_bar.*


/**
 *@author:
 *@date:2019/9/25 17:28
 *@discription: 节点成员列表
 */

class NodeMemberActivity : BaseOdinActivity<INodeMembersView, NodeMemberPresenter>(), INodeMembersView {

    companion object {
        fun startNodeMemberActivity(context: Context, nodeId: String) {
            context.startActivity(Intent(context, NodeMemberActivity::class.java).apply {
                putExtra("nodeId", nodeId)
            })
        }
    }

    private lateinit var memberListAdapter: NodeMemberListAdapter

    override fun getTitleText(): String {
        return "节点成员列表"
    }

    override fun getLayout(): Int {
        return R.layout.activity_node_member
    }

    override fun initView() {
        initToolbar(commToolBar,commTitle)
        rvMemberList.layoutManager = LinearLayoutManager(mContext)
        memberListAdapter = NodeMemberListAdapter(R.layout.item_node_member)
        rvMemberList.adapter = memberListAdapter
    }

    override fun createPresenter(): NodeMemberPresenter {
        return NodeMemberPresenter()
    }

    override fun createView(): INodeMembersView {
        return this
    }

    override fun initData() {
        presenter.members()
    }

    override fun getNodeId(): String {
        return intent.getStringExtra("nodeId")
    }

    override fun setMembers(members: List<Member>?) {
        memberListAdapter.setNewData(members)
    }
}
